package org.example.flink.operation;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Description :
 * @School:优极限学堂
 * @Official-Website: http://www.yjxxt.com
 * @Teacher:李毅大帝
 * @Mail:863159469@qq.com
 */
public class Hello11SinkCommon {
    public static void main(String[] args) throws Exception {
        //运行环境
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
        environment.setParallelism(2); //会把数据写到俩 个文件中，不会重复写
        //操作数据
        DataStreamSource<Integer> source = environment.fromElements(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
        //----打印到控制台
        // source.print("输出到控制台");
        //----写出到文件
        // source.writeAsText("data/text_" + System.currentTimeMillis());
        // source.map(num -> Tuple2.of(num, 666), Types.TUPLE(Types.INT, Types.INT))
        //         .writeAsCsv("data/csv_" + System.currentTimeMillis());
        //----写出到Socket
        // DataStreamSink<Integer> integerDataStreamSink = source.writeToSocket("192.168.88.101", 20523, new SerializationSchema<Integer>() {
        //     @Override
        //     public  byte[]serialize(Integer element) {
        //         return element.toString().getBytes(StandardCharsets.UTF_8);
        //     }
        // });

        //运行环境
        environment.execute();
    }
}
